import java.util.Date

class Rent {
	
	Book book

	String user

	Date beginDate = new Date()

	Date returnedDate = null

	String description

	static constraints = {
		book(nullable: false)
		user(blank: false)
		returnedDate(nullable:true)
	}

	def returnBook() {
		this.returnedDate = new Date()		
		this.save()	
	}

	static List findAllRented() {
		return Rent.findAllByReturnedDateIsNull();
	}

	static List findAllReturned() {
		return Rent.findAllByReturnedDateIsNotNull();
	}

	def boolean canReturnBook() {
		return (this.returnedDate == null);
	}

}
